<html>
<head>
  <meta HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=ISO-8859-1">
  <title>rsrbf.m</title>
<link rel="stylesheet" type="text/css" href="../../m-syntax.css">
</head>
<body>
<code>
<span class=defun_kw>function</span>&nbsp;<span class=defun_out>red_model&nbsp;</span>=&nbsp;<span class=defun_name>rsrbf</span>(<span class=defun_in>model,options</span>)<br>
<span class=h1>%&nbsp;RSRBF&nbsp;Redused&nbsp;Set&nbsp;Method&nbsp;for&nbsp;RBF&nbsp;kernel&nbsp;expansion.</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Synopsis:</span></span><br>
<span class=help>%&nbsp;&nbsp;red_model&nbsp;=&nbsp;rsrbf(model)</span><br>
<span class=help>%&nbsp;&nbsp;red_model&nbsp;=&nbsp;rsrbf(model,options)</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Description:</span></span><br>
<span class=help>%&nbsp;&nbsp;red_model&nbsp;=&nbsp;rsrbf(model)&nbsp;searchs&nbsp;for&nbsp;a&nbsp;kernel&nbsp;expansion</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;with&nbsp;nsv&nbsp;vectors&nbsp;which&nbsp;best&nbsp;approximates&nbsp;the&nbsp;input&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;expansion&nbsp;given&nbsp;in&nbsp;model&nbsp;[Schol98a].&nbsp;The&nbsp;Radial&nbsp;Basis&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;kernel&nbsp;(RBF)&nbsp;is&nbsp;assumed&nbsp;(see&nbsp;'help&nbsp;kernel').</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;red_model&nbsp;=&nbsp;rsrbf(model,options)&nbsp;allows&nbsp;to&nbsp;specify&nbsp;the&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;control&nbsp;paramaters.</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Input:</span></span><br>
<span class=help>%&nbsp;&nbsp;model&nbsp;[struct]&nbsp;Kernel&nbsp;expansion:</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;.Alpha&nbsp;[nsv&nbsp;x&nbsp;1]&nbsp;Weight&nbsp;vector.</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;.sv.X&nbsp;[dim&nbsp;x&nbsp;nsv]&nbsp;Vectors&nbsp;defining&nbsp;the&nbsp;expansion.</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;.options.ker&nbsp;[string]&nbsp;Must&nbsp;be&nbsp;equal&nbsp;to&nbsp;'rbf'.</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;.options.arg&nbsp;[1x1]&nbsp;Kernel&nbsp;argument&nbsp;(see&nbsp;'help&nbsp;kernel').</span><br>
<span class=help>%&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;options&nbsp;[struct]&nbsp;Control&nbsp;parameters:</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;.nsv&nbsp;[1x1]&nbsp;Desired&nbsp;number&nbsp;of&nbsp;vectors&nbsp;in&nbsp;the&nbsp;reduced&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;expansion&nbsp;(default&nbsp;round(length(model.Alpha)/2)).</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;.eps&nbsp;[1x1]&nbsp;Desier&nbsp;limit&nbsp;on&nbsp;the&nbsp;norm&nbsp;of&nbsp;difference&nbsp;between&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;the&nbsp;original&nbsp;&nbsp;normal&nbsp;vector&nbsp;and&nbsp;the&nbsp;reduced&nbsp;the&nbsp;normal&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vector&nbsp;in&nbsp;the&nbsp;&nbsp;feature&nbsp;space.&nbsp;The&nbsp;algorithm&nbsp;is&nbsp;stopped&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when&nbsp;a&nbsp;lower&nbsp;&nbsp;difference&nbsp;is&nbsp;achived&nbsp;(default&nbsp;1e-6).</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;.preimage&nbsp;[string]&nbsp;Function&nbsp;called&nbsp;to&nbsp;solve&nbsp;the&nbsp;RBF&nbsp;pre-image&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;problem&nbsp;(default&nbsp;'rbfpreimg');</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;.verb&nbsp;[1x1]&nbsp;If&nbsp;1&nbsp;then&nbsp;progress&nbsp;info&nbsp;is&nbsp;display&nbsp;(default&nbsp;0).</span><br>
<span class=help>%&nbsp;</span><br>
<span class=help>%&nbsp;<span class=help_field>Output:</span></span><br>
<span class=help>%&nbsp;&nbsp;red_model&nbsp;[struct]&nbsp;Reduced&nbsp;kernel&nbsp;expansion.</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Example:</span></span><br>
<span class=help>%&nbsp;&nbsp;trn&nbsp;=&nbsp;load('riply_trn');</span><br>
<span class=help>%&nbsp;&nbsp;model&nbsp;=&nbsp;smo(trn,struct('ker','rbf','arg',1,'C',10));</span><br>
<span class=help>%&nbsp;&nbsp;red_model&nbsp;=&nbsp;rsrbf(model,struct('nsv',10));</span><br>
<span class=help>%&nbsp;&nbsp;figure;&nbsp;ppatterns(trn);</span><br>
<span class=help>%&nbsp;&nbsp;h1&nbsp;=&nbsp;pboundary(model,struct('line_style','r'));</span><br>
<span class=help>%&nbsp;&nbsp;h2&nbsp;=&nbsp;pboundary(red_model,struct('line_style','b'));</span><br>
<span class=help>%&nbsp;&nbsp;legend([h1(1)&nbsp;h2(1)],'Original&nbsp;SVM','Reduced&nbsp;SVM');</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;See&nbsp;also&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;RBFPREIMG.</span><br>
<span class=help>%</span><br>
<hr>
<span class=help1>%&nbsp;<span class=help1_field>About:</span>&nbsp;Statistical&nbsp;Pattern&nbsp;Recognition&nbsp;Toolbox</span><br>
<span class=help1>%&nbsp;(C)&nbsp;1999-2003,&nbsp;Written&nbsp;by&nbsp;Vojtech&nbsp;Franc&nbsp;and&nbsp;Vaclav&nbsp;Hlavac</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://www.cvut.cz"&gt;Czech&nbsp;Technical&nbsp;University&nbsp;Prague&lt;/a&gt;</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://www.feld.cvut.cz"&gt;Faculty&nbsp;of&nbsp;Electrical&nbsp;Engineering&lt;/a&gt;</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://cmp.felk.cvut.cz"&gt;Center&nbsp;for&nbsp;Machine&nbsp;Perception&lt;/a&gt;</span><br>
<br>
<span class=help1>%&nbsp;<span class=help1_field>Modifications:</span></span><br>
<span class=help1>%&nbsp;11-oct-2004,&nbsp;VF,&nbsp;knorm.m&nbsp;used&nbsp;</span><br>
<span class=help1>%&nbsp;21-sep-2004,&nbsp;VF</span><br>
<span class=help1>%&nbsp;10-jun-2004,&nbsp;VF</span><br>
<span class=help1>%&nbsp;02-dec-2003,&nbsp;VF</span><br>
<br>
<hr>
<span class=comment>%&nbsp;process&nbsp;inputs</span><br>
<span class=comment>%--------------------------------------------------</span><br>
<span class=keyword>if</span>&nbsp;<span class=stack>nargin</span>&nbsp;&lt;&nbsp;2,&nbsp;options=[];&nbsp;<span class=keyword>else</span>&nbsp;options&nbsp;=&nbsp;c2s(options);&nbsp;<span class=keyword>end</span><br>
<span class=keyword>if</span>&nbsp;~isfield(options,<span class=quotes>'nsv'</span>),&nbsp;options.nsv&nbsp;=&nbsp;round(length(model.Alpha)/2);&nbsp;<span class=keyword>end</span><br>
<span class=keyword>if</span>&nbsp;~isfield(options,<span class=quotes>'eps'</span>),&nbsp;options.eps&nbsp;=&nbsp;1e-6;&nbsp;<span class=keyword>end</span><br>
<span class=keyword>if</span>&nbsp;~isfield(options,<span class=quotes>'preimage'</span>),&nbsp;options.preimage&nbsp;=&nbsp;<span class=quotes>'rbfpreimg2'</span>;&nbsp;<span class=keyword>end</span><br>
<span class=keyword>if</span>&nbsp;~isfield(options,<span class=quotes>'verb'</span>),&nbsp;options.verb&nbsp;=&nbsp;0;&nbsp;<span class=keyword>end</span><br>
<br>
<span class=comment>%&nbsp;init</span><br>
<span class=comment>%--------------------------------------------------</span><br>
Z=[];<br>
Beta&nbsp;=&nbsp;[];<br>
Alpha&nbsp;=&nbsp;model.Alpha(:);<br>
X&nbsp;=&nbsp;model.sv.X;<br>
<span class=comment>%Const&nbsp;=&nbsp;Alpha'*kernel(X,&nbsp;model.options.ker,&nbsp;model.options.arg&nbsp;)*Alpha;</span><br>
Const&nbsp;=&nbsp;knorm(X,Alpha,model.options.ker,model.options.arg)^2;<br>
<span class=error>error</span>&nbsp;=&nbsp;inf;<br>
iter&nbsp;=&nbsp;0;<br>
<br>
<span class=comment>%&nbsp;main&nbsp;loop</span><br>
<span class=comment>%--------------------------------------------------</span><br>
<span class=keyword>while</span>&nbsp;<span class=error>error</span>&nbsp;&gt;&nbsp;options.eps&nbsp;&&nbsp;iter&nbsp;&lt;&nbsp;options.nsv,<br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;iter&nbsp;=&nbsp;iter&nbsp;+&nbsp;1;<br>
<br>
&nbsp;&nbsp;<span class=keyword>if</span>&nbsp;options.verb,&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;<span class=io>fprintf</span>(<span class=quotes>'Iteration&nbsp;%d:&nbsp;'</span>,&nbsp;iter);<br>
&nbsp;&nbsp;<span class=keyword>end</span><br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;tmp_model.Alpha&nbsp;=&nbsp;Alpha;<br>
&nbsp;&nbsp;tmp_model.sv.X&nbsp;=&nbsp;X;<br>
&nbsp;&nbsp;tmp_model.options&nbsp;=&nbsp;model.options;<br>
<br>
&nbsp;&nbsp;<span class=keyword>if</span>&nbsp;options.verb,&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=io>fprintf</span>(<span class=quotes>'computing&nbsp;preimage,&nbsp;'</span>);<br>
&nbsp;&nbsp;<span class=keyword>end</span><br>
<span class=comment>%&nbsp;&nbsp;Z&nbsp;=&nbsp;[Z,&nbsp;rbfpreimg2(tmp_model)];</span><br>
&nbsp;&nbsp;Z&nbsp;=&nbsp;[Z,&nbsp;<span class=eval>feval</span>(&nbsp;options.preimage,tmp_model)];<br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;Kz&nbsp;=&nbsp;kernel(&nbsp;Z,&nbsp;model.options.ker,&nbsp;model.options.arg&nbsp;);<br>
&nbsp;&nbsp;Kzs&nbsp;=&nbsp;kernel(&nbsp;Z,&nbsp;model.sv.X,&nbsp;model.options.ker,&nbsp;model.options.arg&nbsp;);<br>
&nbsp;&nbsp;Beta&nbsp;=&nbsp;inv(&nbsp;Kz&nbsp;)&nbsp;*&nbsp;Kzs&nbsp;*&nbsp;model.Alpha(:);<br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;<span class=error>error</span>&nbsp;=&nbsp;Const&nbsp;+&nbsp;Beta<span class=quotes>'*Kz*Beta&nbsp;-&nbsp;2*Beta'</span>*Kzs*model.Alpha(:);<br>
&nbsp;&nbsp;<span class=keyword>if</span>&nbsp;options.verb,&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=io>fprintf</span>(<span class=quotes>'||w-w_red||^2&nbsp;=&nbsp;%f\n'</span>,&nbsp;<span class=error>error</span>);<br>
&nbsp;&nbsp;<span class=keyword>end</span><br>
<br>
&nbsp;&nbsp;Alpha&nbsp;=&nbsp;[model.Alpha(:);&nbsp;-Beta(:)]';<br>
&nbsp;&nbsp;X&nbsp;=&nbsp;[model.sv.X,&nbsp;Z];<br>
&nbsp;&nbsp;<br>
<span class=keyword>end</span><br>
<br>
red_model&nbsp;=&nbsp;model;<br>
red_model.Alpha&nbsp;=&nbsp;Beta;<br>
red_model.sv.X&nbsp;=&nbsp;Z;<br>
red_model.nsv&nbsp;=&nbsp;size(Z,2);<br>
<br>
<span class=jump>return</span>;<br>
<span class=comment>%EOF</span><br>
</code>
